﻿namespace Microsoft.SharePoint.Client.Utilities
{
    using Microsoft.SharePoint.Client;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.Utilities.Utility", ServerTypeId="{16f43e7e-bf35-475d-b677-9dc61e549339}")]
    public class Utility : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public Utility(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public static ClientResult<string> CreateEmailBodyForInvitation(ClientRuntimeContext Context, string pageAddress)
        {
            ClientAction query = new ClientActionInvokeStaticMethod("{16f43e7e-bf35-475d-b677-9dc61e549339}", "CreateEmailBodyForInvitation", new object[] { pageAddress });
            Context.AddQuery(query);
            ClientResult<string> result = new ClientResult<string>();
            Context.AddQueryIdAndResultObject(query.Id, result);
            return result;
        }

        [Remote]
        public static ListItem CreateNewDiscussion(ClientRuntimeContext Context, List list, string title)
        {
            return new ListItem(Context, new ObjectPathStaticMethod(Context, "{16f43e7e-bf35-475d-b677-9dc61e549339}", "CreateNewDiscussion", new object[] { list, title }));
        }

        [Remote]
        public static ListItem CreateNewDiscussionReply(ClientRuntimeContext Context, ListItem parent)
        {
            return new ListItem(Context, new ObjectPathStaticMethod(Context, "{16f43e7e-bf35-475d-b677-9dc61e549339}", "CreateNewDiscussionReply", new object[] { parent }));
        }

        [Remote]
        public static ClientResult<string> FormatDateTime(ClientRuntimeContext Context, Web web, DateTime datetime, Microsoft.SharePoint.Client.Utilities.DateTimeFormat format)
        {
            ClientAction query = new ClientActionInvokeStaticMethod("{16f43e7e-bf35-475d-b677-9dc61e549339}", "FormatDateTime", new object[] { web, datetime, format });
            Context.AddQuery(query);
            ClientResult<string> result = new ClientResult<string>();
            Context.AddQueryIdAndResultObject(query.Id, result);
            return result;
        }

        [Remote]
        public static ClientResult<string> GetCurrentUserEmailAddresses(ClientRuntimeContext Context)
        {
            ClientAction query = new ClientActionInvokeStaticMethod("{16f43e7e-bf35-475d-b677-9dc61e549339}", "GetCurrentUserEmailAddresses", null);
            Context.AddQuery(query);
            ClientResult<string> result = new ClientResult<string>();
            Context.AddQueryIdAndResultObject(query.Id, result);
            return result;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }

        [Remote]
        public static ClientResult<PrincipalInfo> ResolvePrincipal(ClientRuntimeContext Context, Web web, string input, PrincipalType scopes, PrincipalSource sources, UserCollection usersContainer, bool inputIsEmailOnly)
        {
            if (Context.ValidateOnClient)
            {
                if (web == null)
                {
                    throw ClientUtility.CreateArgumentNullException("web");
                }
                if ((input != null) && (input.Length > 0xff))
                {
                    throw ClientUtility.CreateArgumentException("input");
                }
            }
            ClientAction query = new ClientActionInvokeStaticMethod("{16f43e7e-bf35-475d-b677-9dc61e549339}", "ResolvePrincipal", new object[] { web, input, scopes, sources, usersContainer, inputIsEmailOnly });
            Context.AddQuery(query);
            ClientResult<PrincipalInfo> result = new ClientResult<PrincipalInfo>();
            Context.AddQueryIdAndResultObject(query.Id, result);
            return result;
        }

        [Remote]
        public static IList<PrincipalInfo> SearchPrincipals(ClientRuntimeContext Context, Web web, string input, PrincipalType scopes, PrincipalSource sources, UserCollection usersContainer, int maxCount)
        {
            if (Context.ValidateOnClient)
            {
                if (web == null)
                {
                    throw ClientUtility.CreateArgumentNullException("web");
                }
                if (input == null)
                {
                    throw ClientUtility.CreateArgumentNullException("input");
                }
                if ((input != null) && (input.Length > 0xff))
                {
                    throw ClientUtility.CreateArgumentException("input");
                }
            }
            ClientAction query = new ClientActionInvokeStaticMethod("{16f43e7e-bf35-475d-b677-9dc61e549339}", "SearchPrincipals", new object[] { web, input, scopes, sources, usersContainer, maxCount });
            Context.AddQuery(query);
            IList<PrincipalInfo> list = new List<PrincipalInfo>();
            Context.AddQueryIdAndResultObject(query.Id, new ClientListResultHandler<PrincipalInfo>(list));
            return list;
        }
    }
}

